---
title: OJS data exploration
date: last-modified
categories: [Analysis,Learning-Curve, R, OJS]
page-layout: full
code-fold: show
code-tools: true
execute:
warning: false
eval: true
---
```{r}
pacman:: p_load (tidyverse,here)
d <- readRDS (here ("data/dPrune-01-19-23.rds" ))
# Prepare the data for analysis
dtest <- d %>%
filter (expMode %in% c ("test-Nf" , "test-train-nf" )) %>%
group_by (id, lowBound) %>%
mutate (nBand = n (), band = bandInt, id = factor (id)) %>%
group_by (id) %>%
mutate (nd = n_distinct (lowBound))
dtest <- dtest %>%
group_by (id, lowBound) %>%
filter (nBand >= 5 & nd == 6 )
dtest <- dtest %>%
group_by (id) %>%
filter (! id %in% unique (dtest$ id[dtest$ nBand < 5 ]))
dtestAgg <- dtest %>%
group_by (id, condit, catOrder, feedbackType, vb, band, lowBound, highBound, input) %>%
mutate (vxCapped = ifelse (vx > 1600 , 1600 , vx)) %>%
summarise (
vxMean = mean (vx), devMean = mean (dist), vxMed = median (vx), devMed = median (dist),
vxMeanCap = mean (vxCapped), .groups = "keep"
)
ds1 <- d %>%
filter (expMode %in% c ("train" , "train-Nf" , "test-Nf" , "test-train-nf" )) %>%
filter (! id %in% unique (dtest$ id[dtest$ nBand < 5 ]), vx< 1500 ) %>%
select (id, condit, catOrder, feedbackType, expMode, trial, gt.train, vb, band, bandInt, lowBound, highBound, input, vx, dist, vxb)
ojs_define (dso= ds1)
```
```{ojs}
import { aq, op } from "@uwdata/arquero"
//data = FileAttachment("palmer-penguins.csv").csv({ typed: true })
//ds1=transpose(ds1)
ds= transpose (dso)
Plot. plot ({
facet : {
data : ds,
x : "condit" ,
y : "bandInt" ,
marginRight : 80
},
marks : [
Plot. frame (),
Plot. rectY (ds,
Plot. binX (
{y : "count" },
{x : "vx" , thresholds : 50 , fill : "bandInt" } // thresholds = number of bins
)
),
Plot. tickX (ds,
Plot. groupZ (
{x : "count" },
{x : "vx" ,
z : d => ds. condit + ds. bandInt ,
stroke : "#333" ,
strokeWidth : 2
}
)
)
],
x : {label : "Vx" , domain : [0 , 1800 ], grid : true },
})
Plot. plot ({
marks : [
Plot. line (ds, {
x : "gt.train" , // feature for the x channel
y : "vx" , // feature for the y channel
fill : "condit" ,
stroke : "vb" ,
}),
],
x : {label : "Trial Number" },
y : {label : "Vx" , domain : [0 , 1800 ], grid : true },
color : {legend : true , scheme : "Turbo" , type : "categorical" },
width : 400 ,
height : 400
});
Plot. plot ({
grid : true ,
marks : [
Plot. rectY (ds, Plot. binX ({y : "count" }, {x : "vx" , fill : "condit" , fy : "condit" })),
Plot. ruleY ([0 ])
]
})
Plot. rectY (ds, Plot. binX ({y : "count" }, {x : "condit" , fill : "condit" })). plot ()
Plot. line (ds, {x : "gt.train" , y : "vx" , fill : "condit" }). plot ({y : {grid : true }})
d = aq. from (ds)
d
. groupby ("condit" , "vb" , "feedbackType" , "expMode" , "catOrder" )
. rollup ({mean_vx : d => op. mean (d. vx )}, {mean_dist : d => op. mean (d. dist )})
. view (15 )
dt = aq. from (ds)
dtAgg = dt
. filter (dt => dt. expMode === "train" )
. groupby ("condit" , "vb" , "gt.train" )
. rollup ({mean_vx : dt => op. mean (dt. vx )}, {mean_dist : dt => op. mean (dt. dist )})
Plot. line (dtAgg, {x : "gt.train" , y : "mean_vx" , fill : "vb" }). plot ({y : {grid : true }})
Plot. plot ({
grid : true ,
marginRight : 60 ,
facet : {
data : dtAgg,
x : "condit" ,
y : "vb" ,
marginRight : 80
},
marks : [
Plot. frame (),
Plot. lineY (dtAgg, {
x : "gt.train" ,
y : "mean_vx" ,
fill : "vb"
})
]
})
dtAgg
. view (25 )
```